/*
Naijanimi Free SMS Application for Nokia mobiles.

"Naijanimi Free SMS Application" is protected by the copyright law
(c) 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
Distributed under the LGPL 3.0 license.

This file is part of "Naijanimi Free SMS Application".

    "Naijanimi Free SMS Application" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Naijanimi Free SMS Application" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "Naijanimi Free SMS Application".
    If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.0

Flipable {
    id: container

    // Properties used to manage the flipping angle and
    // the axis along the objects should rotate.
    property bool flipped: false
    property int xAxis: 0
    property int yAxis: 0
    property int angle: 0

    signal programfunctionsClicked

    width: 300
    height: 300

    // ---------------------------------------------------------- START DEBUG BLOCK
    // Debug info.
    // For debug console messages use debugMessage(msg) instead of console.log(msg)
    // in the source module set baseMsg property with the string that should appear
    // before any debug message on the console.
    // To disable debug, set debugStatus to false. This can be done also only in some
    // code blocks.
    property bool debugStatus: true
    property string baseMsg: "*** Debug FlipForms: "
    function debugMessage(msg) { if (debugStatus == true) console.log(baseMsg + msg); }
    // ---------------------------------------------------------- END DEBUG BLOCK


    // Front elements
    // Main layout is used to decide what to do at startup, so depending by the
    // button user can access to login or registration form.
    front: MainLayout {
        id: firstscreen
        width: container.width
        height: container.height
        // Before inverting the flipt status, the right form will be shown and the other
        // remain hidden
        onBtnloginClicked: {
            backForms.login_opacity = 1
            backForms.register_opacity = 0
            container.flipped = !container.flipped; debugMessage("Invert Flip Status")
        }
        onBtnregisterClicked: {
            backForms.login_opacity = 0
            backForms.register_opacity = 1
            container.flipped = !container.flipped; debugMessage("Invert Flip Status")
        }
    }

    // Back elements
    // BackForms contains the two main forms for login or register. When one of the forms
    // has a buttonclick that closes the form, the page is flipped to the front view.
    // No other action should be done at this level before the flip action.
    back: BackForms {
        id: backForms
        width: container.width
        height: container.height
        onExitformsClicked: {
            container.flipped = !container.flipped; debugMessage("Invert Flip Status")
        }
        onLoginformsClicked: { container.programfunctionsClicked(); debugMessage("Login clicked") }
    }

    state: "front"

    transform: Rotation {
        id: rotation; origin.x: container.width / 2; origin.y: container.height / 2
        axis.x: container.xAxis; axis.y: container.yAxis; axis.z: 0
    }

    states: State {
        name: "front"; when: container.flipped
        PropertyChanges { target: rotation; angle: container.angle }
    }

    transitions: Transition {
        ParallelAnimation {
            NumberAnimation { target: rotation; properties: "angle"; duration: 600 }
            SequentialAnimation {
                NumberAnimation { target: container; property: "scale"; to: 0.75; duration: 300 }
                NumberAnimation { target: container; property: "scale"; to: 1.0; duration: 300 }
            }
        }
    }

}
